<?php
class CrontController
{
	function newsletterAction()
	{
		$objSmarty 	= DRX::load("smarty");
		$objCront = new Cront();
		//get news gan day nhat co nhu cau gui newsletter
		if ( !$arrInfoNews = $objCront -> getNewestNews() )
			return false;
		
		//get ra 1 member muon nhan newsletter ma chua gui news nay cho member do
		$arrInfoMember = $objCront -> getMemberSendNews($arrInfoNews['id']);
		if ( !count($arrInfoMember) )
			return false;
		
		foreach ( $arrInfoMember as $intKey => $arrValue )	
		{
			//get email
			include_once "IO_Mailer.php";
			$objMail = new IO_Mailer();
			
			$codeUnscribe = md5(time());
			$strUrlUnscribr = $codeUnscribe . "-" . $arrValue['id'] . "-" . $arrInfoNews['id'];
			$objSmarty -> assign("URL_UNSCRIBE", $strUrlUnscribr);
			$objSmarty -> assign("NEWS_ID", $arrInfoNews['id']);
			$objSmarty -> assign("NEWS_TITLE", $arrInfoNews['title']);
			$objSmarty -> assign("NEWS_SUMMARY", $arrInfoNews['summary']);
			$objSmarty -> assign("NEWS_DETAIL", $arrInfoNews['detail']);
			
			$strContent = $objSmarty -> fetch("cront/newsletter.tpl");
			$strContent = $objMail -> utf_to_iso8859_1($strContent);
			
			//$strToEmail = 'lhthach82@yahoo.com.vn';
			$strToEmail = $arrValue['private_email'];
			if ( $objMail -> send_mail('solvay-mba.edu.vn', $strToEmail, '', '', $arrInfoNews['title'], $strContent, 'alumni@solvay-mba.edu.vn') )
			{
				//insert vao phan da duoc send newsleter cho member nay voi tin nay
				$objCront -> insertCheckNewsletterSuccess($arrValue['id'], $arrInfoNews['id'], $codeUnscribe);
				echo 'Thành công<br>';
			}
			else
					echo 'không thành công';
		}
		
	}	
}
?>